How to get a MySQL field's content with PHP? -
i've been working on website's database , had problem recently: want user read field of row, when field of same row submitted. i.e:
user_id=1 user_name=fran user_pass=potato referedby_id=0 referedby_name=empty
when going inside www.website.com/form.php?referedby_id=1
i want user see "so, fran refered you?"
i've been learning php , decided try this:
$referedbyid = mysqli_real_escape_string($con,$_post["referedby_id"]); //in case it's 1 because of url $sel_referedbyname = "select user_name users user_id='$referedbyid'"; //then should select of user_name "fran" $run_referedbyname = mysqli_query($con, $sel_referedbyname); //then query select $check_referedbyname = mysqli_fetch_field($run_referedbyname); //and 1 content of query's result $refername = $check_refername->user_name; //as query result object want convert text if(isset($_post["register"]) && $check_user == 0 && $check_email == 0 && $pass == $pass2){ //if right , user/email not exist mysqli_query($con,"insert users (user_name, user_email, user_pass, refer_id, refer_name) values ('$user', '$email', '$pass', '$referid', '$refername')"); //it's submitted database other values. mysqli_close($con); //and finish connection db.
the problem when try , check database, referedby_name field empty. syntax error? or because didn't convert text properly?
in case $referedbyname not text, how can convert properly? because i'm using fetch_field function wrong?
additional info: $referedbyid being called (i think) in post form html
<form action="register.php" method="post" onsubmit="validate();"> <table width="500" align="center" bgcolor="skyblue"> <tr align="center"> <td colspan="3"><h2>registrarse</h2></td> </tr> <tr> <td align="right"><b>nombre de usuario:</b></td> <td><input type="text" name="user" required="required"/></td> </tr> <tr> <td align="right"><b>email:</b></td> <td><input type="email" name="email" required="required"/></td> </tr> <tr> <tr> <td align="right"><b>contraseƱa:</b></td> <td><input type="password" id="pass" name="pass" required="required"/></td> </tr> <tr> <td align="right"><b>verificar contraseƱa:</b></td> <td><input type="password" id="pass2" name="pass2" required="required"/></td> </tr> <tr align="center"> <td colspan="3"> <input type="hidden" name="referedby_id" value="<?php echo $_get["referedby_id"]; ?>"/> <input type="submit" name="register" value="registrarse"/></td> </tr> </table> </form>
i don't know why downvotes, tried clear , specific could... anyways, if else has trouble finding the value of specific field use mysqli_fetch_assoc(mysqli_query($conect, $select))['name of sql field']
mysqli_fetch_field($result)
show information field, type of input, name of table, name of column, etc.
hope that's useful same issue. bye.
Comments
Post a Comment