Jump to content

MattD00

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

MattD00's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. <form method="post" action="editindex.php"> <?php //$row["title"] = "title"; //$row["id"] = "id"; $sql = "SELECT * FROM home ORDER BY id ASC"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo "<span id=\"itm1\" onclick=\"exchange(this);\">" . $row['title'] . "</span> <input ondblclick=\"exchange(this);\" id=\"itm1b\" class=\"replace\" type=\"text\ name=\"title\">"; } ?> <input type="submit" value="Save" name="update"> <input type="hidden" name="id" value="<?php $row['id'] ?>" </form> <?php if (isset ($_POST['update'])) { //$row["title"] = "title"; //$row["id"] = "id"; $update = "UPDATE home SET title = '".$_POST['title']."' WHERE id = '" .$_POST['id']."'"; mysql_query($update); } ?>
  2. It is still now workning I have no idea what the problem is. I can never seem to get update queries to work.
  3. I'm an not bothered about the SQL injection right now I just want to get it all working first. It is behind a login so its not my main priority. Thanks for the help.
  4. I am trying to update the content of my website which is all stored in a MySQL database. Currently on the page I am displaying all the data stored in the database using MySQL SELECT and a while loop. Using JavaScript when the text is clicked the element changes into a text box allowing the text to be edited. What I want to do is be able to change the data in the text box and then store it into the database updating the current data. <form method="post" action="editindex.php"> <?php $sql = "SELECT * FROM home ORDER BY id ASC"; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)){ echo "<span id=\"itm1\" onclick=\"exchange(this);\">" . $row['title'] . "</span><input ondblclick=\"exchange(this);\" id=\"itm1b\" class=\"replace\" type=\"text\ name=\"title\">";?> <input type="submit" value="Save" name="submit"> <input type="hidden" name="id" value="<?php $row['id'] ?>" </form> <?php if (isset ($_POST['submit'])) { $update = "UPDATE home SET title=".$_POST['title']." WHERE id=".$_POST['id'].""; mysql_query($update); } ?> I have more text being output from the while loop below but I just want to get it working on the title first. Any ideas of why the update is not working?
  5. I fixed that problem my connect file was using the same variables but now I get SELECT id FROM users WHERE username='' The password shows up fine but the username is blank. Even though the field is called username and username is being used in the query.
  6. From echoing out the query it'sshowing the username and password for phpMyAdmin, instead of the username and password stored in the the table "users".
  7. OK so I have now echoed out the error so that bit is working. However the login is still not working
  8. I was able to fix the mysql_num_rows() there was an error with my database. However nothing happens when I login and no error message is shown when the wrong username or password is entered. I decided to echo out the $count but it just shows up as being 0 when trying to login.
  9. I have tried to create a basic login form. When I enter the username and password I get this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in login.php on line 10 <?php require("connection.php"); if($_SERVER["REQUEST_METHOD"] == "POST") { $username=mysql_real_escape_string($_POST['username']); $password=mysql_real_escape_string($_POST['password']); $password=md5($password); $sql="SELECT id FROM user WHERE username='$username' and password='$password'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { header("location: dashboard.php"); } else { $error="Invalid username or password"; } } ?> <form action="login.php" method="POST"> <table class="ltext"> <tr> <td> Username </td> <td> <input type="text" name="usename" class="input" /> </td> </tr> <tr> <td> Password </td> <td> <input type="password" name="password" class="input" /> </td> </tr> </tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="Login" name="submit" class="input" /> <input type="reset" value="Clear" name="clear" class="input" /> </td> </tr> </table> </form> I can't figure out why I am getting that error message does anyone have any ideas?
  10. I created a form that would display all the information that was in my database within a textbox using a while loop. The infomation is able to be displayed but when trying to update only the information in the last textbox gets updated and the other textboxes will just stay the same. <?php include ('connection.php'); ?> <form method="post" action="update.php"> <?php $display = mysql_query("SELECT * FROM book ORDER BY id asc") or die("Table Error"); $ID = $_POST['id']; $Title = $_POST['title']; $Cost = $_POST['cost']; $Stock = $_POST['stock']; while ($row = mysql_fetch_assoc($display)) { echo "ID :<input type=\"text\" name=\"".id."\" value = \"". $row['id'] ."\"/readonly>"; echo "Title :<input type=\"text\" name=\"".title."\" value = \"" . $row['title'] . "\"/>"; echo "Cost :<input type=\"text\" name=\"".cost."\" value = \"" .$row['cost'] . "\"/>"; echo "Stock :<input type=\"text\" name=\"".stock."\" value = \"" . $row['stock'] . "\"/>"; mysql_query("UPDATE book SET title = '" .$Title. "', cost = '" .$Cost. "', stock = '" .$Stock. "' WHERE id = '" .$ID. "'"); } ?> <input type="submit" name="update" value="Update" /> Im not sure why it is doing this if someone could tell me it would be a big help Thanks
  11. Well i saved the file into xxamps htdocs folder. <?php if (isset($_POST['required'])) { include ('connection.php'); $title = $_POST['title']; $cost = $_POST['cost']; $stock = $_POST['no_in_stock']; $insert = "INSERT INTO book (title, cost, no_in_stock) VALUES ('$title', '$cost', '$stock')"; if ( !mysql_query($connect, $insert) ) { die( "<br>Query string: $insert<br>Failed with error: " . mysql_error($connect) ); } else { if( mysql_affected_rows($connect) > 0 ) { $newrecord = "New record added"; } } } ?> I just got rid of the i on mysqli to make it mysql not sure if that was right or not.
  12. I have change the mysqli to mysql and the error is still the same.
  13. I couldn't get any of it to work because i forgot to add method="post" to the html form. Now that I have the php script will run and i get a Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in F:\xampp\htdocs\RIA\insert.php on line 18 Warning: mysqli_error() expects parameter 1 to be mysqli, resource given in F:\xampp\htdocs\RIA\insert.php on line 19 I tried googling the error but still not sure how to fix it.
  14. I have created a php insert to add data input from a html form into a phpmyadmin database runnig in xxamp. php connect file works fine <?php $connect = mysql_connect("localhost","root","") or die("Connection error"); mysql_select_db("ria") or die(mysql_error()); ?> php code in insert data into database not working <?php if (isset($_POST['required'])) { include ('connection.php'); $title = $_POST['title']; $cost = $_POST['cost']; $stock = $_POST['no in stock']; $insert = "INSERT INTO book (title, cost, no in stock) VALUES ('$title', '$cost', '$stock')"; if (!mysqli_query($connect, $insert)) { die('can not insert new record'); } $newrecord = "New record added"; } ?> HTML forms <form action="Insert.php"> <input type="hidden" name="required" value="true" /> <fieldset> <legend>Insert New Book</legend> <label>Title <input type="text" name="title" /></label> <label>Cost <input type="text" name="cost" /></label> <label>No. in Stock <input type="text" name="no in stock" /> </label> </fieldset> <br /> <input type="submit" value="Submit" /> </form> last bit of php to give a message when data has been added <?php echo $newrecord ?> any suggestions what is wrong with the php.
×
×
  • 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.