Jump to content

pcristian43

Members
  • Posts

    10
  • Joined

  • Last visited

pcristian43's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am trying to build a sql administration app, I know there are some out there but I wanna sharpen my skills.
  2. I was thinking of adding queries using a basic HTML form. To be able to do that I was thinking of having a Query sql table which has all the main create, insert, remove, update, delete and select general syntax into it. The idea is to be able to choose a query based on a HTML select option and add the values to a field, any idea how can you do that dynamically?
  3. Thank you all for your replies but I forgot to mention I want to add data dynamically to the array
  4. I am trying to add new elements to an empty array using a form and submit button and the code is not adding anything from it. Here is the code I use: <!DOCTYPE html> <html> <head> <title> </title> </head> <body> <div class="site"> <div class="menu"> </div> <div class="head"> </div> <div class="content"> <form> <input type="text" value="" name="add"/><br/> <input type="submit" value="Add" name="submit"/> </form> </div> <div class="footer"> </div> </div> </body> </html> <?php $submit = $_POST["submit"]; $field = $_POST["add"]; $list = array(); if($submit){ $psh = array_push($list,$field); echo $list; } ?> Any idea why is it not working?
  5. I also have other general use functions that don't seem to work properly, here are those as well: class Query{ function table($name,$cols){ include 'conx.php'; $query = " CREATE TABLE $name( id int AUTO_INCREMENT PRIMARY KEY NOT NULL, ".$cols.", error varchar(255) NOT NULL, date date NOT NULL ); "; $res = mysqli_query($con,$query) or die(mysqli_error($con)); if($res){ echo "Table created"; }else{ echo "Could not run table"; } } function select($table,$col,$val){ include 'conx.php'; $query = " SELECT $col FROM $table WHERE $col='$val'; "; $res = mysqli_query($con,$query); if($res){ echo "Selected data"; }else{ echo "Could not select data"; } } function update($table,$col,$val,$id){ include 'conx.php'; $query = " UPDATE $table SET $col='$val' WHERE id='$id'; ) "; $res = mysqli_query($con,$query); if($res){ echo "Updated value"; }else{ echo "Did not update value"; } } }
  6. Hello I have a general php insert function that I want to use to insert data into tables regulary, the problem is, each time I use it it creates a new row in the table instead of using certain columns to add information to, here is the function, can you tell me why does it insert a new row each time I use it? class Query{ function add($table,$cols,$vals){ include 'conx.php'; $query = " INSERT INTO $table($cols) VALUES('$vals'); "; $res = mysqli_query($con,$query) ; if($res){ echo "Inserted value"; }else{ echo "Did not insert value"; } } }
  7. The script also shows me this error message: Warning: mysqli_query() expects parameter 1 to be mysqli, null given in on line 50. Line 50 is the $res variable.
  8. If it doesn't its seen as a php function instead of SQL one, that's why I placed the quotes.
  9. I tried that already, even escaping strings, it still shows nothing inside the table. The only thing that executes is the CREATE TABLE statement
  10. Hello all, so I created an insert function and it seems no matter what I try that it won't add values using the query function inside a table from the respective variables, I would like to know why is this happening? Here is the code can you tell me why it doesn't insert anything in the database? It shows no errors when it runs but then again when I check the tables they're empty! function insert(){ $user = $_POST['user']; $pass = md5($_POST['pass']); $priv = "User"; $mail = $_POST['mail']; $avatar = $_FILES['avatar']['name']; $date="now()"; $submit = $_POST['submit']; $query = "INSERT INTO user(user,pass,priv,mail,avatar,date) VALUES(`$user`,`$pass`,`$priv`,`$mail`,`$avatar`,`$date`);"; if($submit){ $res = mysqli_query($con,$query) or die(mysqli_error($con)); } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.